<template>
	<view class="main">
		
		<view class="section">
			<view class="title">原小区名称：</view>
			<view class="content">
				<view class="input_bg">
					<input class="input" v-model="name" placeholder="请输入小区名称"></input>
				</view>
			</view>
		</view>
		
		<view class="section">
			<view class="title">新小区名称：</view>
			<view class="content">
				<view class="input_bg">
					<input class="input" v-model="new_name" placeholder="请输入新小区名称"></input>
				</view>
			</view>
		</view>
		<view class="section">
			<view class="title">原始地址：</view>
			<view class="content">
				<view class="input_bg">
					<input class="input" v-model="address" placeholder="请输入原始地址"></input>
				</view>
			</view>
		</view>
		<view class="section">
			<view class="title">所在地址：</view>
			<view class="content">
				<view class="input_bg">
					<input class="input" v-model="new_address" placeholder="请输入所在地址"></input>
					<view class="location" @click="locationEvent()">
						<image class="loc" src="../../static/images/index/location.png"></image>
					</view>
				</view>
			</view>
		</view>
		
		<view class="footer">
			<view class="submit-btn" @click="submitEvent()">确认提交</view>
		</view>
		
	</view><!-- main end-->
</template>

<script>
	// import {image_upload} from "@/api/common";
	import {saveCommunity} from "@/api/community.js";
	export default {
		data() {
			return {
				id:0,
				name:'',
				new_name:'',
				address:'',
				new_address:''
			}
		},
		onLoad(options) {
			this.id = options.id;
			this.name = options.name;
			this.new_name = options.name;
			this.address = options.address;
			this.new_address = options.address;
			
			let that = this;
			let store_data = uni.getStorageSync('storage_key1');
			if(store_data){
				that.id = store_data.id;
				that.name = store_data.name;
				that.new_name = store_data.new_name;
				that.address = store_data.address;
				that.new_address = store_data.new_address;
			}
			console.info(store_data);
		},
		onShareTimeline() {
			return {
				title: '数据采集采集',
				//分享朋友圈的参数
				query: "isShare=1&id=",
			}
		},
		onShareAppMessage(){
		},
		created() {
			
		},
		onShow:function(){
			
			
		},
		onHide:function(){
			this.saveCache();
		},
		onUnload:function(){
			this.saveCache();
		},
		methods: {
			//获取位置
			locationEvent(){
				var _this = this;
				uni.chooseLocation({
					success: (res) => {
				
						//地图选点
						console.log('位置名称：' + res.name);
						console.log('详细地址：' + res.address);
						console.log('纬度：' + res.latitude);
						console.log('经度：' + res.longitude);
						_this.new_address = res.address;
					}
				});
			},
			change(e){
				this.propose_time = e;
			},
			saveCache(){
				var data = {
					id:this.id,
					name:this.name,
					new_name:this.new_name,
					address:this.address,
					new_address:this.new_address
				}
				console.info(data)
				uni.setStorageSync('storage_key1',data);
			},
			delImg(type,index){
				this.pre_imgs.some((item, i)=>{
	　　　　　　　　　　if(i==index){
	　　　　　　　　　　　　this.pre_imgs.splice(i, 1)
	　　　　　　　　　　　　return true;
	　　　　　　　　　　}
	　　　　　　　　})
			},
			choosePhoto(type) {
				let that = this;
				that.$util.uploadImageOne('upload/image', function(res) {
					that.pre_imgs.push(res.data.url);
				});
			},
			resetData(){
				
			},
			submitEvent(){
				if(this.new_name.length == 0){
					uni.showToast({
						title:'请输入新小区名称',
						icon:"none"
					});
					return;
				}
				if(this.new_address.length == 0){
					uni.showToast({
						title:'请输入新地址',
						icon:"none"
					});
					return;
				}
				var data = {
					id:this.id,
					new_name:this.new_name,
					new_address:this.new_address
				}
				console.info(data);
				let that = this;
				uni.showModal({
				  title: '提示信息',
				  content: '确定提交？',
				  cancelText: "取消",
				  confirmText: "确定",
				  confirmColor: '#000',
				  cancelColor: '#ff0000',
				  success: function (res) {
					if (res.confirm) {
						uni.showLoading({
							title:"提交中..."
						});
						saveCommunity(data).then((res)=>{ 
							uni.hideLoading();
							if(res.status == 200){
								that.hasCache = false;
								uni.removeStorageSync('storage_key1')
								uni.showToast({
									title:res.msg,
									icon:"none",
									duration:1000
								});
								setTimeout(1100,function(){
									uni.navigateBack();
								});
							}else{
								uni.showToast({
									title:res.msg
								});
							}
						}).catch((error)=>{
							uni.hideLoading(); 
							console.log(error);
						});
					} else if (res.cancel) {
					  console.log('用户点击取消');
					}
				  }
				});
				
			}
		}
	}
</script>

<style lang="scss">
	page {
	  width: 100%;
	  height: 100%;
	  background-color: white;
	}
	.main {
		display: flex;
		flex-direction: column;
		// align-items: center;
		padding: 30rpx;
		padding-bottom: 0;  
		padding-bottom: constant(safe-area-inset-bottom);  
		padding-bottom: env(safe-area-inset-bottom); 
		.mb100{
			padding-bottom: 150rpx;
		}
		.section{
			display: flex;
			flex-direction: column;
			margin-top: 30rpx;
			.title{
				font-size: 28rpx;
			}
			.content{
				display: flex;
				flex-direction: column; 
				margin-top: 10rpx;
				.input_bg{
					display: flex;
					flex-direction: row;
					align-items: center;
					height: 90rpx;
					border: 1px solid #CCC;
					padding-left: 10rpx;
					padding-right: 10rpx;
					.input{
						font-size: 28rpx;
						height: 90rpx;
						line-height: 90rpx;
						flex: 1;
						margin-right: 15rpx;
						.place{
							color: gray;
						}
						.text{
							color: #000000;
						}
					}
					.date{
						height: 80rpx;
					}
					.location{
						display: flex;
						flex-direction: row;
						margin-right: 15rpx;
						.loc{
							width: 60rpx;
							height:60rpx;
						}
					}
				}
				.text_bg{
					display: flex;
					flex-direction: column;
					height: 160rpx;
					border: 1px solid #CCC;
					padding: 10rpx;
					.textarea{
						font-size: 28rpx;
					}
				}
				.imgs{
					display: flex;
					// padding-left: 10rpx;
					// padding-right: 10rpx;
					flex-direction: row;
					flex-wrap: wrap;
					.item{
						width: 33.3%;
						height:220rpx; 
						.image{ 
							width:85%;
							height:85%;
						}
						.del{
							width:50rpx;
							height:50rpx;
							margin-left: -30rpx;
							margin-top: -20rpx;
							z-index: 99;
							position: absolute;
						}
					}
				}
				.radio{
					margin-top: 15rpx;
					font-size: 28rpx;
				}
				.sign{
					text-align: center;
					height: 300rpx;
					line-height: 300rpx;
					font-size: 28rpx;
					background-color: #F8F8F8;
				}
			}
			.intro{
				font-size: 28rpx;
				color: red;
				margin-top: 15rpx;
			}
			
		}
		.bottom{
			padding-bottom: 150rpx;
		}
	}
	.footer{
		height: 80rpx;
		width: 100%;
		position: fixed;
		right: 0;
		bottom: 0;
		left: 0;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		padding-bottom: 0;  
		padding-bottom: constant(safe-area-inset-bottom);  
		padding-bottom: env(safe-area-inset-bottom); 
		.submit-btn{
			background-color: $uni-main-color;
			color: white;
			font-size: 28rpx;
			height: 80rpx;
			width: 100%;
			text-align: center;
			line-height: 80rpx;
		}
	}
	/****/
	.popup-cls{
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
	}
	
	.pop-info{
		width:100%;
		background-color: white;
		display: flex;
		flex-direction: column;
		.pupop-btn{
			height: 40px;
			display: flex;
			align-items: center;
			padding: 0 30upx;
			justify-content: space-between;
			font-size: 28rpx;
		}
	}
	.pop-top{
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		font-size: 28rpx;
		font-weight: bold;
		color: #000000;
		margin-top: 20rpx;
		text-align: center;
		height: 40rpx;
	}
	
	.center{
		height: 420rpx;
		margin: 30rpx 0rpx 0rpx 0rpx;
		background-color: #F8F8F8;
	}
	
	.bottom{
		display: flex;
		flex-direction: row;
		justify-content: center;
		.btn{
			flex: 1;
			height:80rpx;
			background-color: $uni-main-color;
			// border-radius: 40rpx;
			color: #FFFFFF;
			text-align: center;
			line-height: 80rpx;
			// margin-bottom: 30rpx;
			font-size: 28rpx;
		}
		.mr1{
			margin-right: 1rpx;
		}
	}
	
	.picker-view {
		width: 100%;
		height: 340rpx;
		margin-top: 20rpx;
		.item {
			height: 50px;
			align-items: center;
			justify-content: center;
			text-align: center;
			line-height: 50px;
			font-size: 28rpx;
		}
	}
</style>
